package models

import (
	"conf"
	"fmt"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

func init() {
	runmode := conf.String("runmode")

	// 注册数据库
	aliasName := conf.String("alias_name", runmode)
	dbType := conf.String("db_type", runmode)
	dataSource := fmt.Sprintf(
		"%s:%s@tcp(%s:%s)/%s?charset=utf8",
		conf.String("db_user", runmode),
		conf.String("db_pass", runmode),
		conf.String("db_host", runmode),
		conf.String("db_part", runmode),
		conf.String("db_name", runmode),
	)

	orm.RegisterDataBase(aliasName, dbType, dataSource)
}
